package approval.dao;
//
//import java.sql.CallableStatement;
//import java.sql.PreparedStatement;
//import java.sql.ResultSet;
//import java.sql.SQLException;
//import java.util.ArrayList;
//import java.util.Collection;
//import java.util.Hashtable;
//import java.util.Iterator;
//
//import model.pojo.Employee;
//import models.util.MySqlDataAccessHelper;
//import models.util.UtilInitLang;
//import resource.pojo.Approvedoc;
//import resource.pojo.ListApprove;
//
public class ApprovedocDAO {
	
//
//	public boolean addDailyReport(Approvedoc approvedoc) throws SQLException {
//		int row = 0;
//		PreparedStatement pstmt = null;
//		try {
//			mysqlHelper.open();
//			String query = "insert into approvedoc(Tile,Content,IDEmployee,Timecreate,IDStatus,IDTypeDoc,Description) " +
//					" values(?,?,?,NOW(),?,?,?)";	
//			pstmt = mysqlHelper.getConnection().prepareStatement(query);
//			pstmt.setString(1, approvedoc.getTitle());
//			pstmt.setString(2, approvedoc.getContent());
//			pstmt.setString(3, approvedoc.getiDEmployee());			
//			pstmt.setString(4, "4");
//			pstmt.setString(5, "14");
//			pstmt.setString(6, approvedoc.getDescription());			
//			row = pstmt.executeUpdate();
//		} catch (Exception e) {
//			e.printStackTrace(System.out);
//		} finally {
//			mysqlHelper.close();
//			if (pstmt != null) {
//            	DbUtils.close(pstmt);            	
//            }
//		}
//		return row > 0;
//	}
//
//	public boolean updateDailyReport(Approvedoc approvedoc) throws SQLException {
//		int row = 0;
//		PreparedStatement pstmt = null;
//		try {		
//			mysqlHelper.open();
//			String query = "UPDATE approvedoc SET Tile = ?, Content = ?, " +
//					" Timecreate = NOW(),  Description = ? WHERE IDApproveDoc = ?";	
//			pstmt = mysqlHelper.getConnection().prepareStatement(query);
//			pstmt.setString(1, approvedoc.getTitle());
//			pstmt.setString(2, approvedoc.getContent());
//			pstmt.setString(3, approvedoc.getDescription());			
//			pstmt.setInt(4, approvedoc.getiDApproveDoc());
//			row = pstmt.executeUpdate();			
//		} catch (Exception e) {
//			e.printStackTrace(System.out);
//		} finally {
//			mysqlHelper.close();
//			if (pstmt != null) {
//            	DbUtils.close(pstmt);            	
//            }
//		}
//		return row > 0;
//	}
//	
//	public boolean deleteDailyReport(Approvedoc approvedoc) throws SQLException {
//		int row = 0;
//		PreparedStatement pstmt = null;
//		try {		
//			mysqlHelper.open();
//			String query = "DELETE FROM approvedoc WHERE IDApproveDoc = ?";
//			pstmt = mysqlHelper.getConnection().prepareStatement(query);
//			pstmt.setInt(1, approvedoc.getiDApproveDoc());
//			row = pstmt.executeUpdate();	
//			
//		} catch (Exception e) {
//			e.printStackTrace(System.out);
//		} finally {
//			mysqlHelper.close();
//			if (pstmt != null) {
//            	DbUtils.close(pstmt);            	
//            }
//		}
//		return row > 0;
//	}
//	
//	public Approvedoc getLastRecordDailyReport() {
//		Approvedoc app = new Approvedoc();
//		PreparedStatement pstmt = null;
//		try {
//			mysqlHelper.open();
//			String sql = "SELECT IDApproveDoc,IDGroupApprove,IDEmployee,Tile,Content,Timecreate,IDStatus,IDTypeDoc,Description "
//							+ "FROM approvedoc WHERE approvedoc.IDApproveDoc = ?";							
//			pstmt = mysqlHelper.getConnection().prepareStatement(sql);
//			pstmt.setInt(1, getLastIDRecordDailyReport());
//			ResultSet rs = pstmt.executeQuery();
//			while (rs.next()) {
//				app = new Approvedoc();
//				app.setiDApproveDoc(rs.getInt("IDApproveDoc"));
//				app.setTitle(rs.getString("Tile"));
//				app.setContent(rs.getString("Content"));
//				app.setiDEmployee(rs.getString("IDEmployee"));
//				app.setiDGroupApprove(rs.getString("IDGroupApprove"));
//				app.setTimecreate(rs.getDate("Timecreate"));
//				app.setiDStatus(rs.getInt("IDStatus"));
//				app.setiDTypeDoc(rs.getInt("IDTypeDoc"));
//				app.setDescription(rs.getString("Description"));
//			}
//			ss.setAttribute("document", app);	
//			rs.close();
//		} catch (Exception e) {
//			e.printStackTrace();
//		} finally {
//			mysqlHelper.close();
//		}
//		return app;
//	}
//
//	private int getLastIDRecordDailyReport() {
//		int a = 0;
//		try {
//			mysqlHelper.open();
//			String sql = "SELECT MAX(IDApproveDoc) as  'a' FROM approvedoc";
//			ResultSet rs2 = mysqlHelper.executeQuery(sql);
//			while (rs2.next()) {
//				a = rs2.getInt("a");
//			}
//			rs2.close();
//		} catch (Exception e) {
//			e.printStackTrace();
//		} finally {
//		}
//		return a;
//	}
//
//	private UtilInitLang utilInitLang;
//	private YourDocDAO yourDocDao;
//	private Hashtable<String, String> langs;
//	private Collection<Object> selection;
//	private ArrayList<Approvedoc> allDocApproving = new ArrayList<Approvedoc>();
//	private ArrayList<ListApprove> allListApprove = new ArrayList<ListApprove>();
//	private ArrayList<Approvedoc> allDocApproved = new ArrayList<Approvedoc>();
//	private ArrayList<Approvedoc> allDocSelected = new ArrayList<Approvedoc>();
//	private String scriptDbClickDoc;
//	private String strErrorDbClickDoc = "";
//	private String messErrEdit = "";
//	private String scriptEdit = "";
//	private Approvedoc currentApprovedoc = null;
//	private String scriptApprove = "";
//	private String messErrApprove;
//	private ListApprove curentListApprove = null;
//	private String script = "";
//	private String messErrDecline;
//	private String messErr;
//	private int currentIndex;
//	private int dbRowIndex;
//	private String comment;
//	private static boolean readDoc = true;
//	private boolean check;
//
//	MySqlDataAccessHelper mysqlHelper = new MySqlDataAccessHelper();
//
//	public YourDocDAO getYourDocDao() {
//		return yourDocDao;
//	}
//
//	public ApprovedocDAO getEntityClass() {
//		return this;
//	}
//
//	public void setYourDocDao(YourDocDAO yourDocDao) {
//		this.yourDocDao = yourDocDao;
//	}
//
//	public MySqlDataAccessHelper getMysqlHelper() {
//		return mysqlHelper;
//	}
//
//	public void setMysqlHelper(MySqlDataAccessHelper mysqlHelper) {
//		this.mysqlHelper = mysqlHelper;
//	}
//
//	public UtilInitLang getUtilInitLang() {
//		return utilInitLang;
//	}
//
//	public void setUtilInitLang(UtilInitLang utilInitLang) {
//		this.utilInitLang = utilInitLang;
//	}
//
//	public Hashtable<String, String> getLangs() {
//		langs = getUtilInitLang().getLangs();
//		return langs;
//	}
//
//	public void setLangs(Hashtable<String, String> langs) {
//		this.langs = langs;
//	}
//
//	public void clickDocApproving() {
//		if (getYourDocDao().getAllTempYourDocDelete().size() > 0)
//			getYourDocDao().getAllTempYourDocDelete().clear();
//		allListApprove.clear();
//		Approvedoc ap = allDocApproving.get(this.getCurrentIndex());
//		setCurrentApprovedoc(ap);
//		allListApprove.addAll(ap.getGroupApprove().getAllListApprove());
//	}
//
//	public ApprovedocDAO() {
//
//	}
//
////	public void selectionListener(AjaxBehaviorEvent event) {
////		UIExtendedDataTable dataTable = (UIExtendedDataTable) event
////				.getComponent();
////		Object originalKey = dataTable.getRowKey();
////		allListApprove.clear();
////		for (Object selectionKey : selection) {
////			dataTable.setRowKey(selectionKey);
////			if (dataTable.isRowAvailable()) {
////				Approvedoc ap = (Approvedoc) dataTable.getRowData();
////				allListApprove.addAll(ap.getGroupApprove().getAllListApprove());
////				setCurrentApprovedoc(ap);
////			}
////		}
////		dataTable.setRowKey(originalKey);
////	}
//
//	public ArrayList<Approvedoc> getAllDocApproving() {
//
//		// if (isReadDoc()) {
////		HttpSession ss = (HttpSession) FacesContext.getCurrentInstance()
////				.getExternalContext().getSession(true);
////		mysqlHelper.open();
////		allDocApproving.clear();
////		try {
////			Employee em = (Employee) ss.getAttribute("Employee");
////			String sql = "select * from approvedoc where IDStatus=2 and not ISNULL(IDGroupApprove) and approvedoc.IDEmployee='"
////					+ em.getIdemployee() + "'";
////			ResultSet rs = mysqlHelper.executeQuery(sql);
////			while (rs.next()) {
////				Approvedoc ap = new Approvedoc(rs.getInt("IDApproveDoc"),
////						rs.getString("Tile"), rs.getString("Content"),
////						rs.getString("IDEmployee"),
////						rs.getString("IDGroupApprove"),
////						rs.getDate("Timecreate"), rs.getInt("IDStatus"),
////						rs.getInt("IDTypeDoc"), rs.getDate("TimeApprove"),
////						rs.getString("comment"), rs.getString("Description"));
////				if (checkApproved(ap.getGroupApprove().getAllListApprove()))
////					allDocApproving.add(ap);
////			}
////		} catch (Exception e) {
////			e.printStackTrace();
////		} finally {
////			mysqlHelper.close();
////		}
//		// }
//		// setReadDoc(false);
//		return allDocApproving;
//	}
//
//	public ArrayList<Approvedoc> getAllDocApproved() {
//		mysqlHelper.open();
//		allDocApproved.clear();
//		try {
//			String sql = "select * from approvedoc where IDStatus=1";
//			ResultSet rs = mysqlHelper.executeQuery(sql);
//			while (rs.next()) {
//
//				allDocApproved.add(new Approvedoc(rs.getInt("IDApproveDoc"), rs
//						.getString("Tile"), rs.getString("Content"), rs
//						.getString("IDEmployee"), rs
//						.getString("IDGroupApprove"), rs.getDate("Timecreate"),
//						rs.getInt("IDStatus"), rs.getInt("IDTypeDoc"), rs
//								.getDate("TimeApprove"), rs
//								.getString("comment"), rs
//								.getString("Description")));
//			}
//		} catch (Exception e) {
//		} finally {
//			mysqlHelper.close();
//		}
//		return allDocApproved;
//	}
//
//	public void setAllDocApproved(ArrayList<Approvedoc> allDocApproved) {
//		this.allDocApproved = allDocApproved;
//	}
//
//	// public ArrayList<Approvedoc> getAllyourDoc() {
//	// allyourDoc.clear();
//	// FacesContext f = FacesContext.getCurrentInstance();
//	// HttpSession ss = (HttpSession) f.getExternalContext().getSession(true);
//	// Object obj = ss.getAttribute("Employee");
//	// if (obj != null) {
//	// Employee em = (Employee) obj;
//	// try {
//	// String sql = "select * from approvedoc where IDEmployee="
//	// + em.getiDEmployee();
//	// ResultSet rs = this.ExecuteQuery(sql);
//	// String temp = "";
//	// String tempDecline = "";
//	// while (rs.next()) {
//	// if (rs.getString("StatusApprove").equalsIgnoreCase("0"))
//	// temp = utilInitLang.getViewDocApproving();
//	// else
//	// temp = utilInitLang.getDocApproved();
//	// if (rs.getString("StatusDecline").equalsIgnoreCase("1")) {
//	// tempDecline = utilInitLang.getStatusDecline();
//	// } else {
//	// tempDecline = utilInitLang.getStatusnotDecline();
//	// }
//	// allyourDoc.add(new Approvedoc(rs.getInt("IDApproveDoc"), rs
//	// .getString("Tile"), rs.getString("Content"), rs
//	// .getInt("IDEmployee"), rs.getInt("IDGroupApprove"),
//	// rs.getDate("Timecreate"), temp, tempDecline, rs
//	// .getInt("IDTypeDoc"), rs
//	// .getDate("TimeApprove"), rs
//	// .getString("Description")));
//	// }
//	// } catch (Exception e) {
//	// }
//	// }
//	// return allyourDoc;
//	// }
//	//
//	// public void setAllyourDoc(ArrayList<Approvedoc> allyourDoc) {
//	// this.allyourDoc = allyourDoc;
//	// }
//
//	// ################################### Event #########################
//	public void onDbClickDoc() {
////		FacesContext f = FacesContext.getCurrentInstance();
////		HttpSession ss = (HttpSession) f.getExternalContext().getSession(true);
////		Object obj = ss.getAttribute("Employee");
////		if (obj != null) {
////			models.pojo.Employee em = (models.pojo.Employee) obj;
////			Approvedoc row = allDocApproving.get(this.getDbRowIndex());
////			String IDEm = row.getiDEmployee();
////			if (!em.getIdemployee().equalsIgnoreCase(IDEm)) {
////
////				setStrErrorDbClickDoc(getUtilInitLang().getErrPermissionEdit());
////				setScriptDbClickDoc("RichFaces.ui.PopupPanel.showPopupPanel('popup')");
////			} else {
////				if (checkApproved(row.getGroupApprove().getAllListApprove())) {
////					setStrErrorDbClickDoc(getUtilInitLang()
////							.getErrEditDocApproved());
////					setScriptDbClickDoc("RichFaces.ui.PopupPanel.showPopupPanel('popup')");
////				} else {
////
////					ss.setAttribute("Doc", row);
////					ss.setAttribute("BindingListReceiver", new Boolean(true));
////					ss.setAttribute("BindingCbGroup", new Boolean(true));
////					ss.setAttribute("BindingCbType", new Boolean(true));
////					String strLink = "RichFaces.ui.PopupPanel.hidePopupPanel('popup');openWin('/ERPApprove/changeOrder.jsf?id="
////							+ row.getiDApproveDoc()
////							+ "',750,660,'orderApprove');";
////					setScriptDbClickDoc(strLink);
////				}
////			}
////		} else {
////			setStrErrorDbClickDoc("Something Error!!!");
////			setScriptDbClickDoc("RichFaces.ui.PopupPanel.showPopupPanel('popup')");
////		}
//	}
//
//	private boolean checkApproved(ArrayList<ListApprove> all) {
//		for (ListApprove lst : all) {
//			if (lst.getStatus().getiDStatus() == 5)
//				return true;
//		}
//		return false;
//	}
//
//	public void checkEdit(ActionEvent e) {
////		FacesContext f = FacesContext.getCurrentInstance();
////		HttpSession ss = (HttpSession) f.getExternalContext().getSession(true);
////		Object obj = ss.getAttribute("Employee");
////		if (obj == null)
////			return;
////		Approvedoc ap = getCurrentApprovedoc();
////		Employee em = (Employee) obj;
////		if (ap != null) {
////			if (!ap.getiDEmployee().equalsIgnoreCase(em.getIdemployee())) {
////				setMessErrEdit(getUtilInitLang().getErrPermissionEdit());
////				setScriptEdit("RichFaces.ui.PopupPanel.showPopupPanel('popupPermisstion')");
////			} else {
////				if (getYourDocDao().contains(ap)) {
////					setMessErrEdit(getUtilInitLang().getErrNodocEdit());
////					setScriptEdit("RichFaces.ui.PopupPanel.showPopupPanel('popupPermisstion')");
////					return;
////				}
////				if (checkApproved(ap.getGroupApprove().getAllListApprove())) {
////					setMessErrEdit(getUtilInitLang().getErrPermissionEdit());
////					setScriptEdit("RichFaces.ui.PopupPanel.showPopupPanel('popupPermisstion')");
////					return;
////				}
////				ss.setAttribute("flagRewrite", new Boolean(true));
////				ss.setAttribute("Approvedoc", ap);
////				setMessErrEdit("");
////				setScriptEdit("RichFaces.ui.PopupPanel.hidePopupPanel('popupPermisstion');openWin('/ERPApprove/editDoc.jsf',1000,760,'EditDoc')");
////			}
////		} else {
////			setMessErrEdit(getUtilInitLang().getErrNodocEdit());
////			setScriptEdit("RichFaces.ui.PopupPanel.showPopupPanel('popupPermisstion')");
////		}
//	}
//
//	public void checkEditReceiver(ActionEvent e) {
////		if (currentApprovedoc == null) {
////			setStrErrorDbClickDoc(getUtilInitLang().getErrNodocEdit());
////			setScriptDbClickDoc("RichFaces.ui.PopupPanel.showPopupPanel('popup')");
////			return;
////		}
////		FacesContext f = FacesContext.getCurrentInstance();
////		HttpSession ss = (HttpSession) f.getExternalContext().getSession(true);
////		Object obj = ss.getAttribute("Employee");
////		if (obj != null) {
////			models.pojo.Employee em = (models.pojo.Employee) obj;
////			// Approvedoc row = allDocApproving.get(this.getDbRowIndex());
////			String IDEm = currentApprovedoc.getiDEmployee();
////			if (!em.getIdemployee().equalsIgnoreCase(IDEm)) {
////
////				setStrErrorDbClickDoc(getUtilInitLang().getErrPermissionEdit());
////				setScriptDbClickDoc("RichFaces.ui.PopupPanel.showPopupPanel('popup')");
////			} else {
////				if (checkApproved(currentApprovedoc.getGroupApprove()
////						.getAllListApprove())) {
////					setStrErrorDbClickDoc(getUtilInitLang()
////							.getErrEditDocApproved());
////					setScriptDbClickDoc("RichFaces.ui.PopupPanel.showPopupPanel('popup')");
////				} else {
////
////					ss.setAttribute("Doc", currentApprovedoc);
////					ss.setAttribute("BindingListReceiver", new Boolean(true));
////					ss.setAttribute("BindingCbGroup", new Boolean(true));
////					ss.setAttribute("BindingCbType", new Boolean(true));
////					String strLink = "RichFaces.ui.PopupPanel.hidePopupPanel('popup');openWin('/ERPApprove/changeOrder.jsf?id="
////							+ currentApprovedoc.getiDApproveDoc()
////							+ "',750,660,'orderApprove');";
////					setScriptDbClickDoc(strLink);
////				}
////			}
////		} else {
////			setStrErrorDbClickDoc("Something Error!!!");
////			setScriptDbClickDoc("RichFaces.ui.PopupPanel.showPopupPanel('popup')");
////		}
//	}
//
////	public void checkApprove(ActionEvent e) {
////		Approvedoc ap = this.getCurrentApprovedoc();
////		if (ap != null) {
////			if (checkInListApprove(ap)) {
////				setScriptApprove("RichFaces.ui.PopupPanel.showPopupPanel('pApprove')");
////			} else {
////				setScriptApprove("RichFaces.ui.PopupPanel.showPopupPanel('pErrApprove')");
////			}
////		} else {
////			setMessErrApprove(getUtilInitLang().getErrNoDocApprove());
////			setScriptApprove("RichFaces.ui.PopupPanel.hidePopupPanel('pApprove');RichFaces.ui.PopupPanel.showPopupPanel('pErrApprove')");
////		}
////	}
//
//	public boolean checkInListApprove(Approvedoc ap) {
//
//		FacesContext f = FacesContext.getCurrentInstance();
//		HttpSession ss = (HttpSession) f.getExternalContext().getSession(true);
//		Object obj = ss.getAttribute("Employee");
//
//		if (obj != null) {
//			Employee em = (Employee) obj;
//			ArrayList<ListApprove> appListApp = ap.getGroupApprove()
//					.getAllListApprove();
//
//			for (int i = 0; i < appListApp.size(); i++) {
//				ListApprove lst = appListApp.get(i);
//				if (lst.getiDEmployee().equalsIgnoreCase(em.getIdemployee())) {
//					if (lst.getTypeApprove().getIdTypeApprove() == 2) {
//						setMessErrApprove(getUtilInitLang().getMessApprove());
//						setCurentListApprove(lst);
//						return true;
//					}
//					if (lst.getiDStatus() == 5) {
//						setMessErrApprove(getUtilInitLang().getErrDocApproved());
//						setCurentListApprove(null);
//						return false;
//					} else if (i == 0 && lst.getiDStatus() == 4) {
//						setMessErrApprove(getUtilInitLang().getMessApprove());
//						setCurentListApprove(lst);
//						return true;
//					} else {
//						ListApprove temp = appListApp.get(i - 1);
//						if (temp.getiDStatus() == 4) {
//							setMessErrApprove(getUtilInitLang()
//									.getErrPermissionApprove());
//							setCurentListApprove(null);
//							return false;
//						} else {
//							setMessErrApprove(getUtilInitLang()
//									.getMessApprove());
//							setCurentListApprove(lst);
//							return true;
//						}
//					}
//				}
//			}
//		}
//		setMessErrApprove(getUtilInitLang().getErrPermissionApprove());
//		setCurentListApprove(null);
//		return false;
//	}
//
//	public void approve(ActionEvent e) {
//		mysqlHelper.open();
//		try {
//			ListApprove lst = getCurentListApprove();
//			Approvedoc app = getCurrentApprovedoc();
//			if (lst != null) {
//				if (lst.getTypeApprove().getIdTypeApprove() == 2) {
//					String sqlApp = "update approvedoc set IDStatus=1 where IDApproveDoc="
//							+ app.getiDApproveDoc();
//					String sqlLst = "update listapprove set IDStatus=5,DateApprove=NOW() where ID="
//							+ lst.getIdListApprove();
//					mysqlHelper.executeUpdate(sqlApp);
//					mysqlHelper.executeUpdate(sqlLst);
//					setCurentListApprove(null);
//					setCurrentApprovedoc(null);
//					allListApprove.clear();
//					return;
//				}
//				ArrayList<ListApprove> appListApp = app.getGroupApprove()
//						.getAllListApprove();
//				int lastOrder = appListApp.get(appListApp.size() - 1)
//						.getOrder();
//				if (lastOrder == lst.getOrder()) {
//					String sqlApp = "update approvedoc set IDStatus=1 where IDApproveDoc="
//							+ app.getiDApproveDoc();
//					String sqlLst = "update listapprove set IDStatus=5,DateApprove=NOW() where ID="
//							+ lst.getIdListApprove();
//					mysqlHelper.executeUpdate(sqlApp);
//					mysqlHelper.executeUpdate(sqlLst);
//					allListApprove.clear();
//					setCurentListApprove(null);
//					setCurrentApprovedoc(null);
//				} else {
//					String sqlLst = "update listapprove set IDStatus=5,DateApprove=NOW() where ID="
//							+ lst.getIdListApprove();
//					mysqlHelper.executeUpdate(sqlLst);
//					allListApprove.clear();
//					allListApprove.addAll(app.getGroupApprove()
//							.getAllListApprove());
//					setCurentListApprove(null);
//				}
//			}
//		} catch (Exception ex) {
//
//		} finally {
//			mysqlHelper.close();
//		}
//	}
//
//	public void checkDecline(ActionEvent e) {
//		Approvedoc ap = getCurrentApprovedoc();
//		FacesContext f = FacesContext.getCurrentInstance();
//		HttpSession ss = (HttpSession) f.getExternalContext().getSession(true);
//		if (ap != null) {
//
//			ArrayList<ListApprove> appList = ap.getGroupApprove()
//					.getAllListApprove();
//			Employee em = (Employee) ss.getAttribute("Employee");
//			for (ListApprove lst : appList) {
//				if (lst.getiDEmployee().equalsIgnoreCase(em.getIdemployee())
//						&& lst.getStatus().getiDStatus().intValue() == 4) {
//					setScript("RichFaces.ui.PopupPanel.showPopupPanel('pDecline')");
//					return;
//				}
//			}
//			setMessErrDecline(getUtilInitLang().getErrPermissionDecline());
//			setScript("RichFaces.ui.PopupPanel.showPopupPanel('pErrDecline')");
//		} else {
//			setMessErrDecline(getUtilInitLang().getErrNoDocDecline());
//			setScript("RichFaces.ui.PopupPanel.showPopupPanel('pErrDecline')");
//		}
//	}
//
//	public void showDiaLogComment(ActionEvent e) {
//		setScript("RichFaces.ui.PopupPanel.hidePopupPanel('pDecline');RichFaces.ui.PopupPanel.showPopupPanel('pComment')");
//	}
//
//	public void decline(ActionEvent e) {
//		mysqlHelper.open();
//		try {
//			FacesContext f = FacesContext.getCurrentInstance();
//			HttpSession ss = (HttpSession) f.getExternalContext().getSession(
//					true);
//			Object obj = ss.getAttribute("Employee");
//			if (obj == null)
//				return;
//			Employee em = (Employee) obj;
//			String sql = "update approvedoc set IDStatus=3,comment='"
//					+ this.getComment() + "' where IDApproveDoc="
//					+ getCurrentApprovedoc().getiDApproveDoc();
//			String sqlLst = "update listapprove set IDStatus=3 where IDEmployee='"
//					+ em.getIdemployee() + "'";
//			mysqlHelper.executeUpdate(sqlLst);
//			mysqlHelper.executeUpdate(sql);
//			allListApprove.clear();
//			comment = "";
//			setCurrentApprovedoc(null);
//		} catch (Exception ex) {
//		} finally {
//			mysqlHelper.close();
//		}
//	}
//
//	public void onCancelComment(ActionEvent e) {
//		comment = "";
//	}
//
//	// public void checkView(ActionEvent e) {
//	// FacesContext f = FacesContext.getCurrentInstance();
//	// HttpSession ss = (HttpSession) f.getExternalContext().getSession(true);
//	// Object obj = ss.getAttribute("Employee");
//	// if (obj == null)
//	// return;
//	// Approvedoc ap = getCurrentApprovedoc();
//	// Employee em = (Employee) obj;
//	// if (ap != null) {
//	// if (!ap.getiDEmployee().equalsIgnoreCase(em.getIdemployee())) {
//	// if (!checkInListApprove(ap, em)) {
//	// setMessErr(getUtilInitLang().getErrPermissionViewDoc());
//	// setScript("RichFaces.ui.PopupPanel.showPopupPanel('pView')");
//	// } else {
//	// if (getYourDocDao().contains(ap)) {
//	// setMessErr(getUtilInitLang().getErrNoDocView());
//	// setScript("RichFaces.ui.PopupPanel.showPopupPanel('pView')");
//	//
//	// return;
//	// }
//	// ss.setAttribute("flagRewrite", new Boolean(true));
//	// ss.setAttribute("Approvedoc", ap);
//	// setMessErr("");
//	// setScript("RichFaces.ui.PopupPanel.hidePopupPanel('pView');openWin('/ERPApprove/viewDoc.jsf',1000,760,'EditDoc')");
//	// }
//	// } else {
//	// if (getYourDocDao().contains(ap)) {
//	// setMessErr(getUtilInitLang().getErrNoDocView());
//	// setScript("RichFaces.ui.PopupPanel.showPopupPanel('pView')");
//	// return;
//	// }
//	// ss.setAttribute("flagRewrite", new Boolean(true));
//	// ss.setAttribute("Approvedoc", ap);
//	// setMessErr("");
//	// setScript("RichFaces.ui.PopupPanel.hidePopupPanel('pView');openWin('/ERPApprove/viewDoc.jsf',980,760,'EditDoc')");
//	// }
//	// } else {
//	// setMessErr(getUtilInitLang().getErrNoDocView());
//	// setScript("RichFaces.ui.PopupPanel.showPopupPanel('pView')");
//	// }
//	// }
//	private ArrayList<Approvedoc> allDocSelect = new ArrayList<Approvedoc>();
//
//	public ArrayList<Approvedoc> getAllDocSelect() {
//		return allDocSelect;
//	}
//
//	public void setAllDocSelect(ArrayList<Approvedoc> allDocSelect) {
//		this.allDocSelect = allDocSelect;
//	}
//
//	public void selectDocApproved(AjaxBehaviorEvent e) {
//		Approvedoc ap = (Approvedoc) e.getComponent().getAttributes()
//				.get("approvedoc");
//		if (allDocSelect.contains(ap))
//			allDocSelect.remove(ap);
//		else
//			allDocSelect.add(ap);
//	}
//
//	public void checkView(ActionEvent e) {
//		FacesContext f = FacesContext.getCurrentInstance();
//		HttpSession ss = (HttpSession) f.getExternalContext().getSession(true);
//		if (allDocSelect.size() == 1) {
//			ss.setAttribute("flagRewrite", new Boolean(true));
//			ss.setAttribute("Approvedoc", allDocSelect.get(0));
//			setMessErr("");
//			setScript("RichFaces.ui.PopupPanel.hidePopupPanel('pView');openWin('/ERPApprove/viewDoc.jsf',1000,760,'EditDoc')");
//		} else {
//			if (allDocSelect.size() <= 0) {
//				setMessErr(getUtilInitLang().getErrNoDocView());
//				setScript("RichFaces.ui.PopupPanel.showPopupPanel('pView')");
//			} else {
//				setMessErr(getUtilInitLang().getErrcheckOneView());
//				setScript("RichFaces.ui.PopupPanel.showPopupPanel('pView')");
//			}
//		}
//	}
//
//	public void checkDelete(ActionEvent e) {
//		if (allDocSelect.size() == 0) {
//			setMessErr(getUtilInitLang().getNodocSelected());
//			setScript("RichFaces.ui.PopupPanel.showPopupPanel('pErrDelete')");
//			return;
//		} else {
//			setMessErr(getUtilInitLang().getMessDelete());
//			setScript("RichFaces.ui.PopupPanel.showPopupPanel('pDelete')");
//		}
//	}
//
//	public void deleteDocument(ActionEvent e) {
//		for (Approvedoc ap : allDocSelect)
//			deleteDoc(ap);
//		allDocSelect.clear();
//	}
//
//	private void deleteDoc(Approvedoc ap) {
//		try {
//			mysqlHelper.open();
//			CallableStatement callstm = mysqlHelper.getConnection()
//					.prepareCall("{call deleteDoc(?)}");
//			callstm.setInt(1, ap.getiDApproveDoc());
//			callstm.execute();
//		} catch (Exception e2) {
//		} finally {
//			allListApprove.clear();
//			currentApprovedoc = null;
//			mysqlHelper.close();
//		}
//	}
//
//	private boolean checkInListApprove(Approvedoc ap, Employee em) {
//		ArrayList<ListApprove> list = ap.getGroupApprove().getAllListApprove();
//		for (ListApprove lst : list) {
//			if (lst.getiDEmployee().equalsIgnoreCase(em.getIdemployee()))
//				return true;
//		}
//		return false;
//	}
//
//	public void checkDeleteDoc(ActionEvent e) {
//
//		if (currentApprovedoc == null) {
//			setMessErr(getUtilInitLang().getNodocSelected());
//			setScript("RichFaces.ui.PopupPanel.showPopupPanel('pErrDelete')");
//			return;
//		}
//		FacesContext f = FacesContext.getCurrentInstance();
//		HttpSession ss = (HttpSession) f.getExternalContext().getSession(true);
//		Object obj = ss.getAttribute("Employee");
//		if (obj != null) {
//			models.pojo.Employee em = (models.pojo.Employee) obj;
//			// Approvedoc row = allDocApproving.get(this.getDbRowIndex());
//			String IDEm = currentApprovedoc.getiDEmployee();
//			if (!em.getIdemployee().equalsIgnoreCase(IDEm)) {
//				setMessErr(getUtilInitLang().getErrDeleteDoc());
//				setScript("RichFaces.ui.PopupPanel.showPopupPanel('pErrDelete')");
//			} else {
//				if (checkApproved(currentApprovedoc.getGroupApprove()
//						.getAllListApprove())) {
//					setMessErr(getUtilInitLang().getErrDeleteDoc());
//					setScript("RichFaces.ui.PopupPanel.showPopupPanel('pErrDelete')");
//				} else {
//					setMessErr(getUtilInitLang().getMessDelete());
//					setScript("RichFaces.ui.PopupPanel.showPopupPanel('pDelete')");
//				}
//			}
//		} else {
//			setMessErr("Something Error!!!");
//			setScript("RichFaces.ui.PopupPanel.showPopupPanel('pDelete')");
//		}
//		//
//		// if (this.getCurrentApprovedoc() == null) {
//		// setMessErr(getUtilInitLang().getNodocSelected());
//		// setScript("RichFaces.ui.PopupPanel.showPopupPanel('pErrDelete')");
//		// }else{
//		// setMessErr(getUtilInitLang().getMessDelete());
//		// setScript("RichFaces.ui.PopupPanel.showPopupPanel('pDelete')");
//		// }
//	}
//
//	public void deleteDoc(ActionEvent e) {
//		try {
//			mysqlHelper.open();
//			CallableStatement callstm = mysqlHelper.getConnection()
//					.prepareCall("{call deleteDoc(?)}");
//			callstm.setInt(1, this.getCurrentApprovedoc().getiDApproveDoc());
//			callstm.execute();
//		} catch (Exception e2) {
//		} finally {
//			allListApprove.clear();
//			currentApprovedoc = null;
//			mysqlHelper.close();
//		}
//	}
//
//	public void selectDoc(AjaxBehaviorEvent e) {
//		FacesContext f = FacesContext.getCurrentInstance();
//		// UIExtendedDataTable table = (UIExtendedDataTable) f.getViewRoot()
//		// .findComponent("form1:table");
//		// List<UIComponent> it = table.getChildren();
//		// UIColumn columnCheck = (UIColumn) it.get(0);
//		// List<UIComponent> listComp = columnCheck.getChildren();
//		// HtmlSelectBooleanCheckbox check = (HtmlSelectBooleanCheckbox)
//		// listComp
//		// .get(0);
//		// HtmlSelectBooleanCheckbox compCheckBox = (HtmlSelectBooleanCheckbox)
//		// table
//		// .findComponent(check.getId());
//		// Boolean value1 = (Boolean) compCheckBox.getValue();
//		//
//		// Integer ID = (Integer) e.getComponent().getAttributes()
//		// .get("IDApprove");
//		// for (Approvedoc app : allDocApproving) {
//		// if (app.getiDApproveDoc().equals(ID)) {
//		// if (!value1) {
//		// app.setCheckAddReceiver(false);
//		// setCurrentApprovedoc(null);
//		// } else {
//		// app.setCheckAddReceiver(true);
//		// setCurrentApprovedoc(app);
//		// }
//		// } else{
//		// app.setCheckAddReceiver(false);
//		//
//		// }
//		// }
//
//		// currentApprovedoc = (Approvedoc) e.getComponent().getAttributes()
//		// .get("approvedoc");
//		// setAllListApprove(currentApprovedoc.getGroupApprove().getAllListApprove());
//		Approvedoc ap = (Approvedoc) e.getComponent().getAttributes()
//				.get("approvedoc");
//		if (allDocSelect.contains(ap))
//			allDocSelect.remove(ap);
//		else
//			allDocSelect.add(ap);
//		setAllListApprove(ap.getGroupApprove().getAllListApprove());
//	}
//
//	public String getCheckBoxClientId() {
//		FacesContext context = FacesContext.getCurrentInstance();
//		UIViewRoot root = context.getViewRoot();
//
//		final String componentId = "checkBox";
//		UIComponent c = findComponent(root, componentId);
//		return c.getClientId(context);
//	}
//
//	private UIComponent findComponent(UIComponent c, String id) {
//		if (id.equals(c.getId())) {
//			return c;
//		}
//		Iterator<UIComponent> kids = c.getFacetsAndChildren();
//		while (kids.hasNext()) {
//			UIComponent found = findComponent(kids.next(), id);
//			if (found != null) {
//				return found;
//			}
//		}
//		return null;
//	}
//
//	public void setAllDocApproving(ArrayList<Approvedoc> allDocApproving) {
//		this.allDocApproving = allDocApproving;
//	}
//
//	public Collection<Object> getSelection() {
//		return selection;
//	}
//
//	public void setSelection(Collection<Object> selection) {
//		this.selection = selection;
//	}
//
//	public ArrayList<ListApprove> getAllListApprove() {
//		if (allDocApproving.size() == 0)
//			allListApprove.clear();
//		else if (this.getCurrentApprovedoc() != null) {
//			if (getYourDocDao().contains(this.getCurrentApprovedoc()))
//				allListApprove.clear();
//		}
//		return allListApprove;
//
//	}
//
//	public void setAllListApprove(ArrayList<ListApprove> allListApprove) {
//		this.allListApprove = allListApprove;
//	}
//
//	public String getScriptDbClickDoc() {
//		return scriptDbClickDoc;
//	}
//
//	public void setScriptDbClickDoc(String scriptDbClickDoc) {
//		this.scriptDbClickDoc = scriptDbClickDoc;
//	}
//
//	public String getStrErrorDbClickDoc() {
//		return strErrorDbClickDoc;
//	}
//
//	public void setStrErrorDbClickDoc(String strErrorDbClickDoc) {
//		this.strErrorDbClickDoc = strErrorDbClickDoc;
//	}
//
//	public String getScriptEdit() {
//		return scriptEdit;
//	}
//
//	public void setScriptEdit(String scriptEdit) {
//		this.scriptEdit = scriptEdit;
//	}
//
//	public Approvedoc getCurrentApprovedoc() {
//		return currentApprovedoc;
//	}
//
//	public void setCurrentApprovedoc(Approvedoc currentApprovedoc) {
//		this.currentApprovedoc = currentApprovedoc;
//	}
//
//	public String getMessErrEdit() {
//		return messErrEdit;
//	}
//
//	public void setMessErrEdit(String messErrEdit) {
//		this.messErrEdit = messErrEdit;
//	}
//
//	public String getScriptApprove() {
//		return scriptApprove;
//	}
//
//	public void setScriptApprove(String scriptApprove) {
//		this.scriptApprove = scriptApprove;
//	}
//
//	public String getMessErrApprove() {
//		return messErrApprove;
//	}
//
//	public void setMessErrApprove(String messErrApprove) {
//		this.messErrApprove = messErrApprove;
//	}
//
//	public ListApprove getCurentListApprove() {
//		return curentListApprove;
//	}
//
//	public void setCurentListApprove(ListApprove curentListApprove) {
//		this.curentListApprove = curentListApprove;
//	}
//
//	public String getScript() {
//		return script;
//	}
//
//	public void setScript(String script) {
//		this.script = script;
//	}
//
//	public String getMessErrDecline() {
//		return messErrDecline;
//	}
//
//	public void setMessErrDecline(String messErrDecline) {
//		this.messErrDecline = messErrDecline;
//	}
//
//	public String getMessErr() {
//		return messErr;
//	}
//
//	public void setMessErr(String messErr) {
//		this.messErr = messErr;
//	}
//
//	public int getCurrentIndex() {
//		return currentIndex;
//	}
//
//	public void setCurrentIndex(int currentIndex) {
//		this.currentIndex = currentIndex;
//	}
//
//	public int getDbRowIndex() {
//		return dbRowIndex;
//	}
//
//	public void setDbRowIndex(int dbRowIndex) {
//		this.dbRowIndex = dbRowIndex;
//	}
//
//	public String getComment() {
//		return comment;
//	}
//
//	public void setComment(String comment) {
//		this.comment = comment;
//	}
//
//	public ArrayList<Approvedoc> getAllDocSelected() {
//		return allDocSelected;
//	}
//
//	public void setAllDocSelected(ArrayList<Approvedoc> allDocSelected) {
//		this.allDocSelected = allDocSelected;
//	}
//
//	public static boolean isReadDoc() {
//		return readDoc;
//	}
//
//	public static void setReadDoc(boolean readDoc) {
//		ApprovedocDAO.readDoc = readDoc;
//	}
//
//	public boolean isCheck() {
//		return check;
//	}
//
//	public void setCheck(boolean check) {
//		this.check = check;
//	}
//
	
	
}
